package com.bimrun.gis;

import com.bimrun.gis.util.HttpClientUtil;
import org.junit.Test;

import java.io.*;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

public class ObjAnalysis {
    @Test
    public void countPoint() throws IOException {
        File file = new File("/Users/admin/Downloads/geometry/f07a65e5-bbea-4c16-816e-14f787bfa557_1.obj");
        BufferedReader read = new BufferedReader(new FileReader(file));
        String line = null;
        List<String> vList = new ArrayList<>();
        List<String> vnList = new ArrayList<>();
        List<String> vtList = new ArrayList<>();
        while ((line = read.readLine()) != null) {
            if (line.startsWith("v ")) {
                vList.add(line);
            } else if (line.startsWith("vn ")) {
                vnList.add(line);
            } else if (line.startsWith("vt ")) {
                vtList.add(line);
            }
        }

        HashSet<Object> points = new HashSet<>();
        for (int i = 0; i < vList.size(); i++) {
            String point = vList.get(i) + vnList.get(i) + vtList.get(i);
            int hash = point.hashCode();
            points.add(point);
        }

        System.out.println(points.size());
    }

    volatile AtomicInteger count = new AtomicInteger(0);

    @Test
    public void testThread() throws InterruptedException {
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(8, 50, 1, TimeUnit.MINUTES, new ArrayBlockingQueue<Runnable>(50));

        for (int i = 0; i < 50; i++) {
            Runnable runnable = new Runnable() {
                @Override
                public void run() {
                    try {
                        int a = count.getAndAdd(1);
                        String string = new HttpClientUtil().buildRequest().buildGet(new URI("http://www.baidu.com")).getResponse().getString();
                        System.out.println(a + ":" + string);
                    } catch (IOException e) {
                        e.printStackTrace();
                    } catch (URISyntaxException e) {
                        e.printStackTrace();
                    }
                }
            };
            threadPoolExecutor.submit(runnable);

        }

        Thread.sleep(100000);

    }
}
